﻿using AutoMapper;
using MediatR;
using ProcurementManagement.Applcation.Command.VendorCommand;
using ProcurementManagement.Domain.ProcurementDomain;
using ProcurementManagement.Infrstructre.Interface;

namespace ProcurementManagement.Applcation.CommandHanlers.VendorCommandHanlers
{
    public class VendorBackfillCommandHandlers : IRequestHandler<VendorBackfillCommand, List<Vendor>>
    {
        protected readonly InterfaceVendorRepository repository;
        protected readonly IMapper mapper;
        public VendorBackfillCommandHandlers(InterfaceVendorRepository repository, IMapper mapper)
        {
            this.repository = repository;
            this.mapper = mapper;
        }
        public async Task<List<Vendor>> Handle(VendorBackfillCommand request, CancellationToken cancellationToken)
        {
            var list = (await repository.GetAll()).Where(x => x.VendorId == request.Id).ToList();
            return mapper.Map<List<Vendor>>(list);
        }
    }
}
